﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BaseEntityApi;
using System.IO;
using System.Collections.ObjectModel;

namespace WPF各种控件样式
{
    /// <summary>
    /// Interaction logic for WPFListViewCtrl.xaml
    /// </summary>
    public partial class WPFListViewCtrl : Window
    {
        public WPFListViewCtrl()
        {
            InitializeComponent();
            InitDataToUI();

        }
        /// <summary>
        /// 草稿箱图标
        /// </summary>
        public static Stream Image = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WPF各种控件样式.Resources.t.png");
        public static string imageIco = "/WPF各种控件样式;component/Resources/tick.png";
        private List<TemDataList> GetTemDataList()
        {
            List<TemDataList> tem = new List<TemDataList>();
            tem.Add(new TemDataList() { ID = Guid.NewGuid().ToString(), Details = "详细5", Code = "001.01", Name = "001", ImageIco = Image, IsChecked = true });
            tem.Add(new TemDataList() { ID = Guid.NewGuid().ToString(), Details = "详细4", Code = "002.01", Name = "002", ImageIco = Image, IsChecked = false });
            tem.Add(new TemDataList() { ID = Guid.NewGuid().ToString(), Details = "详细3", Code = "003.01", Name = "003", ImageIco = Image, IsChecked = true });
            tem.Add(new TemDataList() { ID = Guid.NewGuid().ToString(), Details = "详细2", Code = "004.01", Name = "004", ImageIco = Image, IsChecked = false });
            tem.Add(new TemDataList() { ID = Guid.NewGuid().ToString(), Details = "详细1", Code = "005.01", Name = "005", ImageIco = Image, IsChecked = true });
            return tem;

        }
        private void InitDataToUI()
        {
            List<TemDataList> baseData = GetTemDataList();
            //ctrl_data2.ItemsSource = baseData;

            ctrl_Data.CreateListViewDataBindColumns(cbAll_Click, cbOne_Click, "IsChecked", 30, false);
            //ctrl_Data.CreateListViewDataBindColumns("Name", "Name", "ImageIco", 100, new Thickness(0, 2, 2, 2));
            ctrl_Data.CreateListViewDataBindColumns("Code", "Code", 100);
            //ctrl_Data.CreateListViewDataBindColumns("Details", "Details", 200);
            //ctrl_Data.CreateListViewDataBindColumns("Name", "ImageIco", 100, 20, new Thickness(2));
            //ctrl_Data.CreateListViewDataBindColumns("Name", 100);
            ctrl_Data.BindDataToListViewSource<TemDataList>(baseData );
            ctrl_Data.AddRightContexMenu("全选", "cb_00", imageIco, cbAll_Click);
            ctrl_Data.AddRightContexMenu("全选1", "cb_01", imageIco, cbAll_Click);
            ctrl_Data.AddRightContexMenu("全选2", "cb_02", imageIco, cbAll_Click);
            ctrl_Data.AddRightMenuSeparator();
            ctrl_Data.AddRightContexMenu("全选3", "cb_03", imageIco, cbAll_Click);
            ctrl_Data.AddRightContexMenu("全选4", "cb_04", imageIco, cbAll_Click);
            ctrl_Data.AddRightMenuSeparator();
            ctrl_Data.AddRightContexMenu("全选5", "cb_05", imageIco, cbAll_Click);
            ctrl_Data.AddRightContexMenu("全选6", "cb_06", imageIco, cbAll_Click);
            ctrl_Data.MinWidth = 200;

        }

        void cbAll_Click(object sender, RoutedEventArgs e)
        {

        }

        void cbOne_Click(object sender, RoutedEventArgs e)
        {

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<TemDataList> ss = ctrl_Data.DataItemSource as ObservableCollection<TemDataList>;
            TemDataList tem = new TemDataList();
            tem.ID = Guid.NewGuid().ToString();
            tem.Details = "详细6";
            tem.Code = "001.01";
            tem.Name = textBox1.Text.Trim();
            tem.ImageIco = Image;
            tem.IsChecked = true;
            ss.Add(tem);

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<TemDataList> ss = ctrl_Data.DataItemSource as ObservableCollection<TemDataList>;
            TemDataList tem = ctrl_Data.SelectedItem as TemDataList;
            if (tem == null) return;
            foreach (TemDataList item in ss)
            {
                if (item.ID.Equals(tem.ID, StringComparison.OrdinalIgnoreCase))
                {
                    ss.Remove(item);
                    break;
                }
            }

        }
    }
    public class TemDataList : BaseEntity
    {
        public string Code { get; set; }
        public Stream ImageIco { get; set; }
        public bool IsChecked { get; set; }
    }
}
